package ftest.movie.appLogic2;

import ftest.movie.appLogic.FilmHelper;
import ftest.movie.model.Film;

public class FilmHelper2 extends DriverBasedHelper implements FilmHelper {

	public FilmHelper2(ApplicationManager2 manager) {
		super(manager.getWebDriver());
	}

	@Override
	public void create(Film film) {
		pages.mainPage.open();
		pages.mainPage.clickAddButton();
		input(pages.descriptionMoviePage.inputId, film.getId());
		input(pages.descriptionMoviePage.inputImdb, film.getImdb());
		input(pages.descriptionMoviePage.inputTitle, film.getTitle());
		input(pages.descriptionMoviePage.inputSecondName, film.getSecondName());
		input(pages.descriptionMoviePage.inputYear, film.getYear());
		input(pages.descriptionMoviePage.inputDuration, film.getDuration());
		input(pages.descriptionMoviePage.inputRating, film.getRating());
		input(pages.descriptionMoviePage.inputFormat, film.getFormat());
		pages.descriptionMoviePage.selectOwn(film.isOwn());
		pages.descriptionMoviePage.selectHaveSeen(film.isHaveSeen());
		pages.descriptionMoviePage.selectLoanedOut(film.isLoanedOut());
		input(pages.descriptionMoviePage.inputTrailer, film.getTrailer());
		input(pages.descriptionMoviePage.inputNotes, film.getNotes());
		pages.descriptionMoviePage.saveButton.click();
	}

	@Override
	public void delete(Film film) {
		pages.mainPage.clickMovieInMainPage(film.getTitle());
		deleteFromInsidePage();
	}

	@Override
	public void search(String title) {
		pages.mainPage.open();
		input(pages.mainPage.searchField, title);
		clickEnterButton(pages.mainPage.searchField);
	}

	@Override
	public boolean isMoviePresent(String movieName) {
		pages.mainPage.open();
		return isElementPresent(pages.mainPage.movieInMainPage(movieName));
	}

	@Override
	public boolean isValidationTitleMsgPresent() {
		return isElementDisplayed(pages.descriptionMoviePage.validationTitleMsg);
	}

	@Override
	public boolean isNoMoviesFoundMsgPresent() {
		pages.mainPage.open();
		return isElementDisplayed(pages.mainPage.isNoMoviesFoundMsg);
	}

	@Override
	public boolean isValidationYearMsgPresent() {
		return isElementDisplayed(pages.descriptionMoviePage.validationYearMsg);
	}

	@Override
	public boolean isValidationFormatMsgPresent() {
		return isElementDisplayed(pages.descriptionMoviePage.validationFormatMsg);
	}

	@Override
	public void deleteFromInsidePage() {
		pages.insideFilmPage.clickDelete();
		alertOk();
	}

	public void sortAZ() {
		pages.mainPage.open();
		pages.mainPage.clickSortButton();
		pages.mainPage.selectSortAZ();
	}
	
	public void sortZA() {
		pages.mainPage.open();
		pages.mainPage.clickSortButton();
		pages.mainPage.selectSortZA();
	}

	@Override
	public String getFirstInFilmsList() {
		return pages.mainPage.getFirstFilmFromTable();
	}

	@Override
	public String getSecondInFilmsList() {
		return pages.mainPage.getSecondFilmFromTable();
	}

	@Override
	public String getThirdInFilmsList() {
		return pages.mainPage.getThirdFilmFromTable();
	}
}